Introduced a dynamic_pointer_cast to make it work