Added code to handle walls and other obstacles while searching for a path.