Fix #39
Fix #59
Fix #38
Merge pull request #60 from ovatsus/master

Fix for #38, #39 and #59