Placed the keywords fetching code inside a function