Changed code to use array instead of linked list