Some refactoring and some more gui capabilities