Fixed a lot of bugs. Almost done.