moved function from controller to helper