fix typo and memory leak