fixed maxima handling code