Fix tomcat 7 problem  fixes #11 and fixes #9

Not sure why this only happens in tomcat 7, but this solved the problem in both cases for me.