more efficient and prettier hex replacement (thx to @prafuitu)