the max has to be done at the end