Additional cleanup and a bug fix for the new inv code