Simplified code, using more STL and less of custom classes.
used std::pair for searching for redundancies.