Improve config validation.

Fixes #4391