Refactored into new classes. Added unit tests