Fix for #40 and #29
Fix for #31
Merge pull request #42 from adonath/fix_for_#40

Fix for #40, #29 and #31