Fixed a couple memory leaks and issues.