Fixes #42, #41, #40, #39, #38, #37, #36, #35 and #31.