fixed hex conversion and refacotred nesting