move global functions into main controller