modified the logic