Changed resample to avoid memory leak.