Fixed validation and nonce generating logic