refactor function for transport using custom middleware as decorator