Initialize command and flag fields of transactions

This commit adds initialization codes for fields which were left
uninitialized before, potentially leading to segfaults.
Do not reset command count if there are no commands

Prevents another potential segfault.
Merge pull request #543 from neithernut/fix-transaction-init

Initialize command and flag fields of transactions