Moved some code into CUDA source