Fixes #575, #587, #647