improve imputation code