refactor out a common function, delete spare file