Added fix to check for "global" object which may not always be available