Retrying merge.
updated distance code
fixed merge issues