Refactoring. Added specs.
Minor refactoring.