Fix some bugs with --magic-do, and make it work with TCO