Adding/removing packages in the correct order

Dependency order is maintained during add and remove.