remove duplication by factoring shared code to module