updated the logic