Some changes and cleaning up.

A lot of functionality moved to the back-end (again) so that the front end only interacts with the database. History and undo handling now happens in the back end.

Usage of exceptions to make back end testing easy.

Some cleaning up, moving front end stuff to helper methods.