fixed validity tests and separated game loop