Fixed memory leaking bug