Please review rt46407. See commit messages for the motivation behind each change.