Fixed possible memory leak + cleanup