Merge fixes

Hi Curtis, I've restored the needed functionality, made a few small fixes, and removed some obsolete code I had earlier introduced. Otherwise, there's nothing really major in this change. 
Cheers,
Vivek