Fix for issues

Hi, thanks for your piece of code. 
I wrote a fix for some of the issues.

Cheers