refactored to clean up dictionaries