Implementing minimize and maximize.
Fixes #415