fix bugs, add statistics