fixing some memory leaks + typo