Bug fix & optimize.