included KK's segfault patch and fixed unit test accordingly