Factor out validation into its own module.