added some TE methods, fixed gradient bug