Further improvements to stats code. Additional stats queries.