Fix rebooting machine and add corresponding tests