refactored to use an hash look up instead of iterating over an array