A stable version after improving efficiency.