This might be cleaner as a method rather than a class. Also, move it near the end of the file before `toPartition()`.