Fix segfault upon startup

Thanks to Andrei Dziahel for this patch.