tests and some restructuring of game logic