A few fixes

Thanks for a great library!

I found an issue when using the return codes so I've added this fix to my previous pull request.