Fix a few issues.

Fixes #5011 and #5002 .