Fixes #675. Fixes #512. Fixes #546. Other stuff.