factor out common mults, do cudaFrees