I modified the array function to better follow the flowchart.