remove potential usage of -1 as an index