Fix cid generation with mutiple invalid chars