Moved form handling code to its own class.