Refactoring and UI improvements