removed a couple of memory leaks, fixed compute_J and compute_K to not fully replicate the J and K matrices across threads