Fix #525 & #528
Merge pull request #549 from dmp42/maxlen-rewrite-squashed

Bug: Fix #525 & #528