Made cpu implementation easier to convert to GPU implementation