almost completed A*, see README for details