Lots of cleanup plus cardonfile callbacks. Untested.