Changes to cosine similarity code