Code cleanup and protocol fix.