spec and refactor code