Fixed a bug where clearance flattening would return incorrect values