fixed segfault and using correct methods