Correctly handle wifi and keyguard state (hopefully) and other smaller fixes