added dinit function to remove some memory leaks