Refactor code in order to ease unit testing