refactor to expose application and middleware