some optimize
fix segfault