fixed euclidean distance and put in patch sorting