Create data structures and implement the resampling function