Apply .24.2 fix and swamp_ig's fix.

Supersedes swamp_ig's pull request.