Fix #38, partial fix for #18 and fix for #19

See bugs for details
Merge pull request #50 from yaronyg/patch-1

Fix #38, partial fix for #18 and fix for #19