Fix most compilation errors

I fixed all current compilation issues, except that nasty #16.