fixes #38, #39 and #40