adding cosine similarity plus some code cleanup