Fixing segfault error