Fixed occasional errors caused by hex values less than 6 characters

Cleaner way of handling value formatting using format()