Unitary testing and refactoring