Clean up strange level loading code and make it safer