Tidied up the hexad generation code a bit