Added tests for the game engine. Minor refactoring.