spec and refactor codes