Added reworked preprocessing code