Fix preprocess memory usage and correctness