Better error validation.

see #491