Corrected and improved beautify function
Refactored readhex function