check array size before using