Fixed some logic issues.