Uses shared_ptr to take care of input lists