Fixed huge mistake regarding max calculation