How to improve the performance of formatting output - Modular