Patch applied as 867eb0cfb9cce30b49b309c71f02be4cd5f51c28 with a few modifications. Thanks.