Add support for custom validation. Fixes #58