closed resource leaks and cleaned warnings up