added some comments and input length validation from JSON arrays