add callbackFetchKey for flags and improve the code