Implement yz feature and fix memory leak and invalid pointer issue