Several changes; fixes #38 and fixes #39 and fixes #40 and fixes #41