     }
 
     result = NOVA_SUCCESS;
+    if (pomdp_uninitialize_successors_gpu(pomdp) != NOVA_SUCCESS) {
+        result = NOVA_ERROR_DEVICE_FREE;
+    }
+    if (pomdp_uninitialize_state_transitions_gpu(pomdp) != NOVA_SUCCESS) {
+        result = NOVA_ERROR_DEVICE_FREE;
+    }
+    if (pomdp_uninitialize_observation_transitions_gpu(pomdp) != NOVA_SUCCESS) {
+        result = NOVA_ERROR_DEVICE_FREE;
+    }
+    if (pomdp_uninitialize_rewards_gpu(pomdp) != NOVA_SUCCESS) {
+        result = NOVA_ERROR_DEVICE_FREE;
+    }
     if (pomdp_uninitialize_nonzero_beliefs_gpu(pomdp) != NOVA_SUCCESS) {
         result = NOVA_ERROR_DEVICE_FREE;
     }
     if (pomdp_uninitialize_belief_points_gpu(pomdp) != NOVA_SUCCESS) {
-        result = NOVA_ERROR_DEVICE_FREE;
-    }
-    if (pomdp_uninitialize_successors_gpu(pomdp) != NOVA_SUCCESS) {
-        result = NOVA_ERROR_DEVICE_FREE;
-    }
-    if (pomdp_uninitialize_state_transitions_gpu(pomdp) != NOVA_SUCCESS) {
-        result = NOVA_ERROR_DEVICE_FREE;
-    }
-    if (pomdp_uninitialize_observation_transitions_gpu(pomdp) != NOVA_SUCCESS) {
-        result = NOVA_ERROR_DEVICE_FREE;
-    }
-    if (pomdp_uninitialize_rewards_gpu(pomdp) != NOVA_SUCCESS) {
         result = NOVA_ERROR_DEVICE_FREE;
     }
 

    if (result != NOVA_SUCCESS) {
        return result;
    }
    result = pomdp_initialize_successors_gpu(pomdp);
    if (result != NOVA_SUCCESS) {
        return result;
    }
    result = pomdp_initialize_state_transitions_gpu(pomdp);
    if (result != NOVA_SUCCESS) {
        return result;
    }
    result = pomdp_initialize_observation_transitions_gpu(pomdp);
    if (result != NOVA_SUCCESS) {
        return result;
    }
    result = pomdp_initialize_rewards_gpu(pomdp);
    if (result != NOVA_SUCCESS) {
        return result;
    }

    result = pomdp_pbvi_execute_gpu(pomdp, numThreads, Gamma, pi);
    if (result != NOVA_SUCCESS) {

        if (cudaFree(pomdp->d_pi) != cudaSuccess) {
            fprintf(stderr, "Error[pomdp_pbvi_uninitialize_gpu]: %s",
                    "Failed to allocate device-side memory for the pi (the policy).");
            result = NOVA_ERROR_DEVICE_FREE;
        }
    }
    pomdp->d_pi = nullptr;
