Refactored form handler and renderer