Code and tests refactor.