fix bug and plug leak