fixes #16, #17 and #20