fixed leaks, added comments