more comments and rename bufferOffset to rangeOffset to make it clearer what it does