Use a few shared_ptrs to make things slightly neater.