Various memory leaks and callback improvements.