Fixed some minor code flaws