sort globals by scope