Remove duplicates and not working logic