Added deallocation of device memory when the calculations are done.