Debugging distance formula