patched for memory leak