Some fixes for wsgi, and a few bugs