Usually I don\'t even bother posting comments on such snippets, but well here goes:
Why do you use (0 isin %PV)? Did you know this if statement also validates when %pv is 10? or when %pv is 20? Heck every number which contains a zero. This is obviously not what you want, so stop using isin and start using ==.
There is more wrong, but for now bother with this only.