Rewrite removeDuplicateEP to fix order bug