Refactor OpenCL code