Counts and stores in db