Added valid memory range checking.
Refactored hex conversion to be efficient.