Extracted duplicate code into its own method