refactored: placed prefill validation at top.