added saving to savefile and did some cleanup