which.max wasn't working properly, replaced by order