intermediate step, coding the imputation algorithm