array length check fixed; added usage case in sample