Bug fix & code optimize