Apparent Pullup issue

while (x = 1) { //machine state 1 <==== Won't work the way you're expecting

There's a few other convoluted methods in there (read about strlen() among others.