Optimized the hosts removal code