fixing bug in r2 calculation