fix off-by-one-error in changeCount; simplify getting first line of buffer
add some unit tests