optimise the counting of non-zero numbers