switched variable names, changed counting method