Merge performance enhancements from Ambal-master