Refactoring - extract duplicated logic code.