refactored some functions from ocl arithm