Distance algorithms improved and replaced..