Moved function to controller.