Move the code for parsing the given key to its own function. Change-Id: I05eddba48cf7fabd3c48f2175a16457910a47583