Fix bug where number of locations is presumed to be 5, but could in fact be any number depending on the previous function