changed the sequence functions to use the fn:fold functions