format function optimized