added distance logic