modernized cuda code a bit