fixing incorrect min and max bug