basic functionality (n^2 comparisons could be improved)