Fixed grabing function and removed duplicate distance funcion