Refactor common code into own module