added checkDistToStop function