refactored to use two deep hash instead of array index