Added resampling algorithm. Needs validation and documentation!