A couple of bug fixes

Hi there,

I took the liberty to do a code restyling while fixing a couple of bugs (mainly related to uninitialised variables).
We're running the new version in production now and the output is identical to the old one.
It'd be cool if you can pull it into the main repo and perhaps rebuild the deb packages.

Thanks for your script!

Daniele