added memory freeing for parts of the game