Fix min/max to work properly.

This should fix #539