fix bug and performance issue