Distance calculator not working as expected