More functional and more correct line partitioning