fixed bug with log showing incorrect values, improved performance