refactoring and adding tests for UI