Added wall detection function.