Refactoring and UI tweaks