Substituted pivot with grouping for speed.
Also added conditions in convert_dates decorators to avoid unnecessary loops