made changes to karma calculation code