Fixed MAX

Optimization stills needed