refactoried for uwsgi