added a small number in the cosine distance to see if that is what causes the problems