Fixed a lot of bugs (finally).