refactored, fixed nonce