Major refactoring. Now with minimizer!