Fixes #3, #6, #8, #9