copied from dig-extract/dig/prep