Fixed the logic for generating nonce