Fix some leaks and other things