First-last, next-previous function