adapated code to run on data with missing values