Fixed maximize function