fixes for memory leak, performance testing