adds function distance() and method for finding closes safepoint