Increase test coverage to about 90%

We also refactored writeIndex() to make it a bit easier to unit test.

Signed-off-by: Peter Portante <peter.portante@redhat.com>