Add function getBlockCount to do optimization.