move functions to controller