Refactored logic to validate a dictionary (keys and values)
Reuse validate_dict function to reduce code needed
Refactored more code to use validate_dict function
Extracted common functionality into separate function