Bug fix in advance and optimization