Undefined variables

Reformat code in the process
Multiple Undefined indexes