Fixed some bugs in cuda code