Fix array out of bounds segfault