fixed possible memory leaks