added distance calculation