Fixing specs and refactoring