Fixing error in distance computation and rounding distance