I've just pushed this, updated with Carl and Behdad's comments. I may have missed a malloc or two here and there, and please be on the lookout for any arithmetic in malloc arguments in future patches :) - Vlad