`index` can return nil if there is no `"\n"`, which will cause issues later.  Does some other code ensure that `@inbuffer` has newlines?