Fixes #28, #46, #47, #51