Fix access beyond array bounds