Fixed min and max bug where they were inverted.