Fixed major memory leak