Rewrite to make adding new protocols easier