Fixed a bunch of small bugs