Restructure write functionality for more modular output