Partition lists when needed

Fixes #1022