Removed non-array variables being traversed in foreach loops
Fixed a few division by zero errors