moved some functions into the only function that was calling them to limit scope.