Fixed a bunch of minor code issues