added distance calculations
refactorings and additions for json api