merged changes from CUDA version
More CUDA changes