Fix memory leaks and update to new function names