fix segfault reported by Alexander Bokovoy