added a arrayToTree function