refactoring for wsgi usage