adding main idle loop and support for lost device