Fixed and unit-tested finding the closest wall.