Fix variable initiation

The variables was not initiated correctly. In some cases the code crashes and other the QR-code was corrupt. These changes fixes that.