Making ghost distance code