Refactor

This started as a refactoring branch, but turned into a complete re-write of the code. The reason for this is that it turned out that previous refactoring of the code coupled the back-end logic of the game much to tightly with the front-end functionality. The current heavily modified version of the code decouples these to aspects as much as possible.