Fixed the logic