Fix some distance bugs