similar to linked list one, but much easier