fix errors in distance