Move duplicate code into own method

* closes #1