Use Hash#dig to simplify code