fixed memory leaks
fixed indenting