1.2 fixes from master

This is a cherry picked list of all the most important fixes from Master merged for the 1.2 branch.

Signed-off-by: Yan-Fa Li <yanfali@gmail.com>