refactoring code and UI