Make it run on mono

There were some issues on mono (OSX), and these commits fixes that. 
See individual commits for details.