Fixed array out of bounds bug among other things