fixing some memory leaks
formatting