move functions out of controller