Copied in code

from xy tools