Refactored into class pattern. Modified tests.