Clean up, mostly ported.