updated to fetch key more reliably