copied gcm-server code