Fix error with middleware kicking in when it shouldn't