Don't rely on builtin max() function