Using ScopedPointers was causing memory leaks. It's worth tracking down the source of these in the future, but for now, we'll leave the code as it was before.