Switch to using sscanf/hex
Add some comments.
Add error codes.