fix minor issues (memory leak and crash)