fix some leaks and other stuff