new PHP may required to set $var = 0 when iterating

(also cleaned up some stuff… could use a lot more cleaning!)