distance calc - fixing class cast exceptions