Fixed broken detection after wakeup; added unittests