preliminary CUDA work done, CPU version have a couple minor bug fixes