When King David was settled in his palace and the LORD had given him rest from all the surrounding enemies,