fix max calculation