min/max bug fixed