Various fixes and suggestions

Hi,

I took a quick peek at this, and I brought a couple of changes, fixes that will (hopefully) makes it better.
See the commit history below, changes are pretty much explicit.

Regards,
Roland.