make resize fast, fix resource leaks