Added comments and finalized(?) matching algorithm