refactory the code for imputing the data and removing NAs.