solve duplicate code