Thanks for the reply JΛ̊KE.
Actually, I found what was wrong.
There was some piece of code, that did revert things back so that the conditon never got false causing an infinitive loop.
So when getStakeAmount() finally was exceeding the value of maxAmount, then it did revert back to a value that was under the value of maxAmount. So the while-statement was always true.
Once I removed that piece of code, it did work as expected.