Fix some leaks and other stuff