pmd: duplicate code: refactor to minimize dupe code