some optimization & bugfix