minor bugfixes

I added some fixes to make it work in my project
I wonder if you can look and see if there is something useful for you