Fixed some logical issues.