WIP: all tests pass.
Some bug fixes.
Implemented in the GUI.