writing preprocess function