replaced hexval() with something a bit more reliable