Refactor hashes and #to_arabic with while loop