FIXUP: Some cleanup and partitioning into helper methods.