rewritten tensor stuff