Refactor CUDA backend