fixed generate not able to check for duplicates in the wrong order