Minor fixes to ensure array entries exist.  Move maxima code to a single box at the end.