cleaned up cosine distance