moved duplicate code to separate method