Fixed bug with memory leak