Modified the validate function to return null on success, error object on failure.