Bug fixing the back end and creating Junit tests.
Merging part of master.
So many bug fixes.
Merging master in.
Added toString to allow saving and loading of state.