Format code, send payloads, and init curPos