[BACKLOG-207] - Refactoring and adding unit tests