Lots of cleanup for actual implementation.