Applied bug fixes 2ebf1699 and 3733c40 from main line.