clean up performance patch, add some head/tailroom calculation fixes (thx, benoit)