Some refactoring, tests, and GUI related