Fixes #33, #32, #31, #22