refactoring hex decoding method