The Original Code for HEX.