Fix possible corner case in gather script