refactored out more code from global