Rename protocol.py to spec.py and refactor