minor fix to router to extract ids, lats, lons
moved nls function to a function