Fixes #406. Good enough for now, but not perfect.