Fixed bug which caused segfault errors on GPU.