Fixed a lot of small bugs