Refactoring for duplicate codes