Compatible with .Net framework 4.0

Also fix some things.