Refactored code.
Created tests.