Refactored code and fixed few bugs in UI