Improved performance, added auto detect of torch device.