performance fixes and minor tweaks to octet counting