Next shouldn't keep on growing

As far as I can tell, `next` keeps on growing, which can become a problem quickly.
This suggested fix only pushes to `next` when necessary, and clears it when not used.
`else`s have been added to keep the code at the same gzipped size (238 bytes).
In addition, it makes the library a little faster (theoretically).

Warning: even though the test passes, I'm not sure whether `next` is allowed to be cleared;
I got errors when I set it to `null`. I think the current version is harmless though, but please verify.