Merge optimizations/fixes/changes from pami-bgq branch.