fixed possible key generation uniqueness problems and updated models