Statistics collection added. Minor bug fixes.