Improved handling of positions in relation to newlines.