Fix byte index calculation
Add simple test suite, run 'make test' to perform the tests.