Moving duplicate code into its own method