Updated the logic