Small logic fix -- OK to end up at border of image in this code