state persistence logic changed for ssh and usb, code cleanup and bug squashing