Correct and reduce code for proper removal and adding packages