Code cleanup, and fix crash on receive malformed string.