Updated with Torch contributions.