extracted middleware for maintenance mode