fixed MAX/MIN problem