updated hex function