Generalize reduction script