made code more readable by moving the location of the distance += 1