Updated code to be GPU friendly.