Check for end game and tests

Also changed setElment to take 3 arguments. The third one is optional
and it's value. Deffault 1.