Cleanup of function calls to eliminate globals