Fixed the heap space bug