Fixed bugs in preprocessing