Added prepareStage procedure.