remove duplicates inside if..else block