improve document count accuracy
merge with master