fixed bug with segfault