explained what each middleware does in comments