prevent array overflow when window is too small