Trying to fix array access error