Refactoring of unattended-upgrade function