corrected the bug in middleware