Fixes #116, #115, #103, #98.