moved reusable code to a different function

removed creation of form to a diff function