Minor refactoring and adding some specs.