Add matched set reduce method and some refactors