fixing array OOB access bug