Fixed resource leaks