fix out of bounds bug (off by 1 segfault)