Fixed bug that caused massive memory leak.