If I comment out the lines which log the vector x,y,z then the function works.

It seems to have a problem with the vector.