Fix duplicate code problem