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

    }

    result = NOVA_SUCCESS;
    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;
    }



int pomdp_pbvi_uninitialize_gpu(POMDP *pomdp)
{
    int result;

    result = NOVA_SUCCESS;

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