fix segfault and a typo