move main, make wsgi compatible