Refactored form processing into a single routine