fixed the distance from the edge code