Rebased and updated the the patch.