Extracted new functions, replaced duplicates