Added checking to unhex function