rewrite to support wsgi