Replace !cons with standard push
Replace -first with while loops
Replace -group-by with a straight-forward loop