preprocessing function