This branch relands 4fc678c0. There are additional changes to fix the breakage of the original commit.