Refactored code.
Added unit and api specs.