fix bug in count_units