Code cleanup

Let parseHexDigit return an optional instead of a tuple.
Add more test cases.