Fixes #24, #41, #42, #45.