more cleanup and making use of shared_ptr's in API