put extractKeys into a function as suggested by @galfert