moved subsetting code to separate file