Finally comprehensively fixed the shared_ptr header - more cleaning can be done I guess, but most cases are covered here I think.