Fix possible memory leaks
Use correct callback function