moved some common code to the 'tensor' class