Now that I think of it, that error is being thrown because of a table design mismatch. The value you're not seeing is the processed string that is being passed as a key => value into the rs object.
Using that table design, the function will run smooth.
Also, I've found something in the code...