Fixed a bunch of issues for compilation. Still untested.