fixed a huge memory leak