Various fixes and cleanup.