Fixed bug in activity counting