Porting recent fixes & optimizations for 3.0