Clean up code from #597 a bit.