Separating logic from stage to main