Restructure output handling.