Refactoring code and some UI changes