Integrated changes from @miginv