Refactored to use simple arrays instead of linked list