Distance Functions

implemented fixes, still have not tested