Fix bug to dist function