gcm demo code adapted