stwiched back tensor.h, fixed minor bugs