Trying to implement generator instead, can discuss the problem with popping the first element