Fixed some issues found in code and simplified some code.