fixed resource leaks and got rid of unnecessary includes at the top of files