added preprocessing function