Fixed a bunch of bugs, and tried to implement some other features.