Preprocess data function updated