fixing possible resource leaks