Many large changes which should really be split up

- Fix consistency checks
- Factor out methods
- Improve display
Factor out some helpers used by the app and by tests
Testing