abstracted calculation logic into function passed to iteration loop