do not advance pointer if we have a nil element
save the code snippets separately for easier testing and referencing
fourth variation draft
code snippets for fourth-variation