Improve min/max handling. Closes #87.