fixed a few logic issues.