bugfix in middleware