[Ticket #4] Code cleanup, refactoring and tests