some refactoring, spec tests updated