Fix for ordering problem during package removal

Partially fixes #1675