Various crash fixes
Don't call logout until after gcm-unregister otherwise it can fail