Move form creation to function