Fixed the stack level too deep errors by using Hash#invert.