Implemented new dispatcher to handle middleware