add return type for toHex, reformated a few lines