refactor distance API

- pass params to distance
- move intenal modules into separate files
- mode api implementations into separate files
- mode constants into a JSON file