fixed dll_destroy bug, cleaned up code