turns out Math.Max is not good for our needs, replaced with If statemetns
slight change to avoid errors