refactoring for better compatibility with uwsgi and other application se...

...rvers