changes from alobato max qcounts implementation