moved repeating code to separate method