fixed bug where line index could become negative