fixed bug and fixed memory leaks