fix spec and refactor