I don't see why these two variables need to be `global`. They are only used within this function.