Closes patch #785752 and bug #726911. Should be backported after correctness and such has been verified by Fred.