This was using an undefined variable VAL. But based on the other functions VAL is probably supposed to be NAL.