separated preprocess into subfunctions