Refactor code between HEX and Stout.