added better clearance calculation