Fix #9
Fixed possible crash
Fixed possible memory leak