Fix bug on middleware