Fixed two bugs in to_xyz, checked on a test version of MATLAB code.