Fixed more minor bugs and code errors