added distance check