Fixed array out of bounds errors.