Moving variable 'requiredKeys' inside the function that it is used