more specs and some refactoring
More refactoring and handling invalid input