Refactoring and more UI work