Remove duplicates from end, preserve precedence (thanks @sellout :)