Cleaning up some memory leak stuff and polish