extracted code from the view and passed to the controller