Extract validation to external function