simplified track iteration by abstracting common operations into a function