Fixes #28, fixes #38 and fixes #40