Fixed possible memory leaks