fix bug and crash