Using && in combination with arrays may lead to unwanted results.
I had a 'if *<*i>0 && py>0 && py[i-1]>0*>*' clause which failed from time to time until I changed the code to 'if *<**<*i>0*>* && *<*py>0*>* && *<*py[i-1]>0*>**>*'...
PS: as the forum does not like standard brackets I have replaced them by *<* and *>*
PSS: not easy to read now, I know