rearranging for cpp implementation