cleaned up javascript game logic