Port from BEAM: [SBOX-69] Review the distance module