Code cleanup and protocol redefinition