Some fixing and optimization.