Updated to use Lists/LinkedLists instead of an array.