Use #all? instead of #detect
Use functional style to convert the array into hash
Minor changes to improve readability