Partition lists when needed

Fixes #1022 
Did you mean to use this variable for line 889?
If so you can also just use `pollLast()`