Fixed the logic issues