Fixed some bugs so it compiles on linux.
Doesn't work yet.