calculating max correctly.