Cookies

@s-panferov I think this handles everything.

cc @reem 
It would be much faster to slice until 1 before the end, iterator over that with no branches, then append the last one after the for loop.