fix and simplify code for calculating accuracies