Bug fix and optimization.