Fixes #4, #7, #12, #14, #22