Extracted duplicated statements in a function