Split duplicate code into seperate method