App lifecycle fixes