dynamic max calculation