Distance integration

Code tidied
Added support for distance socket (python)