Extracted duplicated code to a new method