Bug fix on calendar middlewware