Change how distance is implemented

 - Distance code is now in /lib folder