Fixed some bug and made it compile properly.

But it still doesn't work.