(Mostly) working code for preprocessing