fixed the bug causing segfault