fixing array OOB bug