factor out nonce into struct
reorganize flags