Ide 1295

Correct the logic and send the pull request again.