solving array length issue