Refactored to work with dictionary.