Major cleanup, reordering.