Be nicer about copying the key.
Append to buf, don't overwrite it.