Rewrote key extraction script