Refactored formatNumber function. Now using all immutable stuff inside the function