Initial implementation for middleware