now keeping & updating counts, instead recomputing them each time (still a bit messy)