optimized powershell
calculating history stats