Replace timing code with a Timer class
Fix end game check