Reorganized CUDA code