Updated format function for speed
Corrected bug