Migrated code for new middleware from test project