Memory leaks and resample rework