Fixing withMaxSize

Actually i haven't fully tested it yet, but this is the following code suggested at first comment and helped me.
Thanks to @bbldg