States, game events, an event queue and ui elements plus code cleanup