Refactor string functions, fix many defects.

That's less than ideal in this case because it keep switching between hex and dec. For code like this in a loop we should just do it manually. 

Removed the extra setw()