some code and UI refactoring