New coding style, event system, states and other minor changes