This seems like a reimplementation of what pkg_add -r does. Why do we need to do it ourselves?