Move processing of scalars to the beginning in Expansion and Compaction

This addresses #218.