Fixed various memory leaks, added dt_destroy_function_data, improved performance and method functions