Fixed CUDA issues (#169, #168, #183, #182)