moving stages to middleware