fix incorrect character accounting with newlines