extracted common code out of method into its own method