Added onChange function and toArray function.