encode key and store as Id field in struct