Add some specs and refactoring