Various bug fixes. Now it actually compiles.