several possible segfault-aware bugs fixed