use max instead of last