Fixing logic issues