Added toArray function to include the properties into the array and
fixed a silly bug