Fixed a lot of minor bugs