Added debugging to (hopefully) help find resample segfault

Basically breaks up resample into a bunch of smaller methods to try to isolate where the segfault occurs. Also incorporates Octavian's changes, so hopefully that fixes things anyway. This should just be temporary.