Updated code with new obstruction detection