Backport #1151 and #1154 from 3.0 branch

This is a decent thing to have in 2.0. This backports it.