Add the minreal function, minor refactoring.
Initial commit