added updated preprocessing function