added i to XY function