Some refactoring and ui stuff